package com.spdd.mt.biz.constant;

import lombok.Getter;

public enum SpddStatus {

    // 系统
    SUCCESS("200", "成功", ""),
    FAILURE("501", "失败", "Other.Inner"),

    // 业务
    SUCCESS_SERVER("00", "成功", ""),
    FAILURE_SERVER("99", "失败", "Other.Inner"),
    AUTH_LOSS("01", "鉴权参数缺失", "Other.Param"),
    PACKAGE_LOSS("02", "话费包ID为空", "Other.Param"),
    USER_LOSS("03", "分发用户为空", "Other.param"),
    PACKAGE_ERROR("04", "话费包ID错误", "ProductInvalid.Empty"),
    PHONE_NUM_ERROR("05", "手机号码格式错误", "AccountInvalid.Format"),
    ORDER_ID_EXIT("06", "订单号重复", "Other.RepeatOrderNo"),
    AUTH_ERROR("07", "鉴权信息错误", "Other.ValidSign"),
    SIGN_FAIL("08", "签名验证失败", "Other.ValidSign"),
    APP_ID_LOSE("09", "APPID已经失效", "Other.AppidExpired"),
    ORDER_NOT_EXISTS("10", "订单号不存在", "Other.OrderNotExists"),
    DATE_ERROR("11", "日期参数错误", "Other.DateExpired"),
    RISK_MANAGE("12", "超出运营商风险控制要求", "Other.RiskManage"),
    OPERATOR_ERROR("13", "运营商类型错误", "Other.OperatorError"),
    OVER_TIME("14", "TIMESTAMP超过时限", "Other.OverTime"),
    SECRET_KEY_ERROR("15", "SECRET_KEY校验错误", "Other.SecretKeyError"),
    PARAM_LOSS("16", "请求参数缺失", "Other.Param"),
    HEADER_LOSS("17", "请求参数HEADER节点缺失", "Other.Param"),
    PHONE_ZONE_ERROR("18", "号码归属和所选产品归属不一致", "ProductInvalid.Area"),
    PRICE_ERROR("19", "结算价格不一致", "ProductInvalid.Settlement"),
    PHONE_ZONE_NOT_EXISTS("20", "手机号查不到地区信息", "AccountInvalid.AreaError"),
    ORDER_ID_ERROR("21", "订单号为空", "Other.OrderIdError"),
    PROVINCE_MAINTAIN("30", "省份维护", "ProductInvalid.Maintain"),
    PRODUCT_MAINTAIN("205", "产品维护", "ProductInvalid.Maintain"),
    BALANCE_NOT_ENOUGH("301", "可用余额不足", "ProductInvalid.Balance"),
    RECORDING_EXISTS("410", "记录已经存在", "Other.Recording"),
    REQUEST_PARAM_ERROR("411", "请求参数不合法", "Other.Param"),
    ACCOUNT_CANCEL_FAIL("412", "款项撤销失败", "Other.AccountCancel"),
    PARAM_ERROR("306", "参数不合法", "Other.Param"),
    CACHE_DATA_LOADING("601", "缓存数据加载中，请稍后再试", "Other.Inner"),
    OSS_UPLOAD_FILE_ERROR("1001", "文件上传失败", "Other.Inner");

    @Getter
    private final String status;

    @Getter
    private final String message;

    @Getter
    private final String problemType;

    SpddStatus(String status, String message, String problemType) {
        this.status = status;
        this.message = message;
        this.problemType = problemType;
    }

    public static SpddStatus getByCode(String code) {
        return getByCode(code, null);
    }

    public static SpddStatus getByCode(String code, SpddStatus defaultStatus) {
        for (SpddStatus spddStatus : SpddStatus.values()) {
            if (spddStatus.status.equals(code)) {
                return spddStatus;
            }
        }
        return defaultStatus;
    }

    public static String getMessageByCode(String code) {
        for (SpddStatus spddStatus : SpddStatus.values()) {
            if (spddStatus.status.equals(code)) {
                return spddStatus.message;
            }
        }
        return "";
    }

    public static String getProblemTypeByCode(String code) {
        for (SpddStatus spddStatus : SpddStatus.values()) {
            if (spddStatus.status.equals(code)) {
                return spddStatus.problemType;
            }
        }
        return "";
    }
}
